home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / amiga / config.a < prev    next >
Text File  |  1994-02-01  |  3KB  |  156 lines

  1.  
  2.         ;   CONFIG.A
  3.         ;
  4.         ;   DiceConfig
  5.         ;
  6.         ;   When the __config keyword is used calls to DiceConfig
  7.         ;   are generated via autoinit code (specifically, the
  8.         ;   autoconfig section).  The sequence is as follows:
  9.         ;
  10.         ;   CALL autoinit0
  11.         ;   CALL autoconfig (calls DiceConfig routine many times)
  12.         ;            args:  len,ptr,rpc,rpc,mode=1
  13.         ;            -opens config file
  14.         ;   CALL autoinit1  (close open config file)
  15.         ;   __main
  16.         ;    <program runs>
  17.         ;   __exit
  18.         ;
  19.         ;   CALL autoconfig (calls DiceConfig routine many times)
  20.         ;            args:  len,ptr,rpc,prc,mode=-1
  21.         ;   CALL autoexit1  (close open config file)
  22.         ;   CALL autoexit0
  23.  
  24.  
  25.         xdef    __DiceConfig
  26.         xdef    __DiceCfgFH
  27.  
  28.         xref    _ConfigFile
  29.         xref    _ConfigVersion
  30.  
  31.         xref    _Open
  32.         xref    _Read
  33.         xref    _Write
  34.         xref    _Close
  35.  
  36.         section libdata,data
  37.  
  38. __DiceCfgFH    ds.l    1
  39. Version     ds.l    1
  40.  
  41.         section autoconfig,code
  42.  
  43.         rts
  44. __DiceConfig    jmp    LongDiceConfig
  45.  
  46.         section autoinit1,code
  47.  
  48.         move.l    __DiceCfgFH(A4),-(sp)
  49.         beq    aiskip
  50.         jsr    _Close
  51.         clr.l    __DiceCfgFH(A4)
  52. aiskip        addq.l    #4,sp
  53.  
  54.         section autoexit1,code
  55.  
  56.         move.l    __DiceCfgFH(A4),-(sp)
  57.         beq    aeskip
  58.         jsr    _Close
  59.         clr.l    __DiceCfgFH(A4)
  60. aeskip        addq.l    #4,sp
  61.  
  62.         ;   rpc,len,ptr,rpc,mode
  63.         ;     4   8    12  16
  64.         ;
  65.         ;   ConfigFile ConfigVersion
  66.  
  67.         section text,code
  68.  
  69. LongDiceConfig
  70.         move.l    16(sp),D0           ; < 0 == SAVE, > 0 == LOAD
  71.         bmi    savecfg
  72.  
  73.         ; -------------- LOAD CONFIG --------------
  74.  
  75.         subq.l    #1,D0            ; 1 = initial open
  76.         bne    lc10            ; wasn't 1
  77.         addq.l    #1,16(sp)           ; 1 -> 2
  78.         tst.l    __DiceCfgFH(A4)     ; file already open?
  79.         bne    lc10
  80.         move.l    _ConfigFile(A4),D0  ; no, file name exists?
  81.         beq    lcret
  82.  
  83.         pea    1005.W            ; open file
  84.         move.l    D0,-(sp)
  85.         jsr    _Open(pc)
  86.         addq.l    #8,sp
  87.         move.l    D0,__DiceCfgFH(A4)  ; open worked?
  88.         beq    lc10
  89.                         ; retrieve version
  90.         pea    4.W
  91.         pea    Version(A4)
  92.         move.l    D0,-(sp)
  93.         jsr    _Read(pc)
  94.         lea    12(sp),sp
  95.         move.l    Version(A4),D0
  96.         cmp.l    _ConfigVersion(A4),D0
  97.         beq    lc10
  98.  
  99.         move.l    __DiceCfgFH(A4),-(sp)   ; error, close file
  100.         jsr    _Close(pc)
  101.         addq.l    #4,sp
  102.         clr.l    __DiceCfgFH(A4)
  103.  
  104.  
  105. lc10        move.l    4(sp),-(sp)
  106.         move.l    8+4(sp),-(sp)
  107.         move.l    __DiceCfgFH(A4),-(sp)
  108.         beq    lc20
  109.         jsr    _Read(pc)
  110. lc20
  111.         lea    12(sp),sp
  112.         bra    lcret
  113.  
  114.  
  115.         ; ----------- SAVE CONFIG
  116. savecfg
  117.         addq.l    #1,D0            ; 1 = initial open
  118.         bne    sc10            ; wasn't 1
  119.         subq.l    #1,16(sp)           ; -1 -> -2
  120.         tst.l    __DiceCfgFH(A4)     ; file already open?
  121.         bne    sc10
  122.         move.l    _ConfigFile(A4),D0  ; no, file name exists?
  123.         beq    lcret
  124.  
  125.         pea    1006.W            ; open file
  126.         move.l    D0,-(sp)
  127.         jsr    _Open(pc)
  128.         addq.l    #8,sp
  129.         move.l    D0,__DiceCfgFH(A4)  ; open worked?
  130.         beq    sc10
  131.  
  132.         ; save version number
  133.  
  134.         pea    4.W
  135.         pea    _ConfigVersion(A4)
  136.         move.l    D0,-(sp)
  137.         jsr    _Write(pc)
  138.         lea    12(sp),sp
  139.  
  140.         ; write config
  141.  
  142. sc10        move.l    4(sp),-(sp)
  143.         move.l    8+4(sp),-(sp)
  144.         move.l    __DiceCfgFH(A4),-(sp)
  145.         beq    sc20
  146.         jsr    _Write(pc)
  147. sc20
  148.         lea    12(sp),sp
  149.  
  150. lcret        move.l    (sp)+,A0
  151.         addq.l    #8,sp
  152.         jmp    (A0)
  153.  
  154.         END
  155.  
  156.